package org.example.ssmDemo.controller;

import com.alibaba.fastjson.JSONObject;
import java.util.List;
import org.example.ssmDemo.service.DoctorInfoService;
import org.example.ssmDemo.service.HospitalService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liangc
 * @version 1.0
 * @Description: 测试业务接口
 * @date: 2021/7/24 18:36
 */
@RestController
@RequestMapping(value = "/v1/api")
public class TestController {

    private static final Logger LOGGER = LoggerFactory.getLogger(TestController.class);

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DoctorInfoService doctorInfoService;

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello() {
        List<String> alias = doctorInfoService.queryHospAlias("一五七医院");
        LOGGER.info("HelloWorld!");
        return "success";
    }

    @ResponseBody
    @RequestMapping(value = "/testRestful/{id}", method = RequestMethod.GET)
    public JSONObject testRestful(@PathVariable String id) {
        LOGGER.info("id: {}", id);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "success");
        return jsonObject;
    }

    @ResponseBody
    @RequestMapping(value = "/runDataFormat", method = RequestMethod.GET)
    public JSONObject runDataFormat() {
        hospitalService.formatHospData();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("code", 200);
        jsonObject.put("msg", "success");
        return jsonObject;
    }

    @RequestMapping(value = "/refreshDoctorInfo", method = RequestMethod.GET)
    public String refreshDoctorInfo() {
        doctorInfoService.refreshDoctorInfo();
        return "success";
    }


}
